package com.bckj.freshnow.goods.service;

import com.bckj.freshnow.goods.entity.GoodsSku;
import com.bckj.freshnow.goods.mapper.GoodsSkuMapper;
import com.bckj.freshnow.goods.repo.GoodsSkuRepository;
import com.bckj.freshnow.goods.convert.GoodsSkuConvert;
import com.bckj.freshnow.goods.model.GoodsSkuResponse;
import com.bckj.freshnow.goods.model.GoodsSkuRequest;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 商品SKU表(GoodsSku)service
 *
 * @author makejava
 * @since 2025-04-22 10:07:45
 */
@Service
@RequiredArgsConstructor
public class GoodsSkuService {

    private final GoodsSkuRepository goodsSkuRepository;
    private final GoodsSkuMapper goodsSkuMapper;
    private final GoodsSkuConvert goodsSkuConvert;
	
    /**
     * 列表
     *
     * @param request req
     * @return list
     */
    public List<GoodsSkuResponse> findAll(GoodsSkuRequest request){
        return goodsSkuMapper.findAll(request);
    }
    
    /**
     * 详情
     *
     * @param id id
     * @return vo
     */
    public GoodsSkuResponse details(Long id) {
        GoodsSku entity = goodsSkuRepository.getById(id);
        return goodsSkuConvert.bean2Response(entity);
    }
    
    /**
	 * 增加
	 *
	 * @param request req
	 * @return boolean
	 */
    public boolean save(GoodsSkuRequest request) {
        GoodsSku data = goodsSkuConvert.request2Bean(request);
        return goodsSkuRepository.save(data);
    }
    
    /**
	 * 修改
	 *
	 * @param request req
	 * @return boolean
	 */
	public boolean update(GoodsSkuRequest request) {
        GoodsSku data = goodsSkuConvert.request2Bean(request);
        return goodsSkuRepository.updateById(data);
	}

	/**
	 * 根据Id移除
	 *
	 * @param id id
	 * @return boolean
	 */
	public boolean remove(Long id) {
		return goodsSkuRepository.removeById(id);
	}

	public List<GoodsSkuResponse> findBySkuCodes(List<String> skuCodes) {
		return goodsSkuMapper.findBySkuCodes(skuCodes);
	}
}

